/**
 * 
 */
package dms.dto;

import java.text.ParseException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import dms.model.Building;
import dms.util.DateFormatUtil;

/**
 * @author 李健
 *
 */
public class DormSupervisorDTO extends ActionForm {
	protected Long id;
	protected Long building;
	protected String name;
	protected String telephone;
	protected String registerDate;
	protected String modifyDate;
	protected String oldEmail;
	protected String email;
	protected String oldPassword;
	protected String password;
	protected String passwordQuestion;
	protected String passwordAnswer;
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * @return the building
	 */
	public Long getBuilding() {
		return building;
	}
	/**
	 * @param building the building to set
	 */
	public void setBuilding(Long building) {
		this.building = building;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the telephone
	 */
	public String getTelephone() {
		return telephone;
	}
	/**
	 * @param telephone the telephone to set
	 */
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	/**
	 * @return the registerDate
	 */
	public Date getRegisterDate() {
		Date date = null;
		
		if (this.registerDate != null) {
			try {
				date = DateFormatUtil.parseDate(this.registerDate);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return date;
	}
	/**
	 * @param registerDate the registerDate to set
	 */
	public void setRegisterDate(String registerDate) {
		this.registerDate = registerDate;
	}
	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}
	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * @return the passwordQuestion
	 */
	public String getPasswordQuestion() {
		return passwordQuestion;
	}
	/**
	 * @param passwordQuestion the passwordQuestion to set
	 */
	public void setPasswordQuestion(String passwordQuestion) {
		this.passwordQuestion = passwordQuestion;
	}
	/**
	 * @return the passwordAnswer
	 */
	public String getPasswordAnswer() {
		return passwordAnswer;
	}
	/**
	 * @param passwordAnswer the passwordAnswer to set
	 */
	public void setPasswordAnswer(String passwordAnswer) {
		this.passwordAnswer = passwordAnswer;
	}
	/**
	 * @return the oldEmail
	 */
	public String getOldEmail() {
		return oldEmail;
	}
	/**
	 * @param oldEmail the oldEmail to set
	 */
	public void setOldEmail(String oldEmail) {
		this.oldEmail = oldEmail;
	}
	/**
	 * @return the oldPassword
	 */
	public String getOldPassword() {
		return oldPassword;
	}
	/**
	 * @param oldPassword the oldPassword to set
	 */
	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		if (password == null || password.length() == 0) {
			errors.add("errors", new ActionMessage("缺少密码", false));
		}
		if (oldPassword == null || oldPassword.length() == 0) {
			errors.add("errors", new ActionMessage("缺少密码", false));
		}
		if (!oldPassword.equals(password)) {
			errors.add("errors", new ActionMessage("密码不一致", false));
		}
		if (email == null || email.length() == 0) {
			errors.add("errors", new ActionMessage("缺少密码", false));
		}
		if (name == null || name.length() == 0) {
			errors.add("errors", new ActionMessage("缺少用户名", false));
		}
		if (passwordQuestion == null || passwordQuestion.length() == 0) {
			errors.add("errors", new ActionMessage("缺少密码问题", false));
		}
		if (passwordAnswer == null || passwordAnswer.length() == 0) {
			errors.add("errors", new ActionMessage("缺少密码答案", false));
		}
		if (building == null) {
			errors.add("errors", new ActionMessage("缺少楼栋", false));
		}
		return errors;
	}
	
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.email = null;
		this.name = null;
		this.oldPassword = null;
		this.passwordAnswer = null;
		this.passwordQuestion = null;
		this.building = null;
		this.password = null;
	}
}
